package cn.ll.action;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.ll.po.RolePermission;
import cn.ll.service.RolePermissionService;

public class RolePermissionAction extends Action {
	
	/**
	 * 添加一条角色和权限的关系
	 * @param request
	 * @param response
	 */
	
	public void save(HttpServletRequest request,HttpServletResponse response){
		String roleid = request.getParameter("roleid");
		String permissionid = request.getParameter("permissionid");
		
		RolePermission rolePermission = new RolePermission();
		rolePermission.setRoleid(roleid);
		rolePermission.setPermid(Integer.parseInt(permissionid));
		RolePermissionService  rolePermissionService = (RolePermissionService) this.getApplicationContext().getBean("rolePermissionService");
		rolePermissionService.save(rolePermission);
		
		Map map = new HashMap();
		map.put("success", true);
		rtn(map, request, response);
		return ;
	}
	
	public void delete(HttpServletRequest request,HttpServletResponse response){
		String rolePermissionId = request.getParameter("id");
		if(rolePermissionId != null && rolePermissionId.length() > 0){
			RolePermissionService  rolePermissionService = (RolePermissionService) this.getApplicationContext().getBean("rolePermissionService");
			RolePermission rolePermission = rolePermissionService.findById(Integer.parseInt(rolePermissionId));
			if(rolePermission != null){
				rolePermissionService.delete(rolePermission);
				Map map = new HashMap();
				map.put("success", true);
				rtn(map, request, response);
				return ;
			}
		}
		Map map = new HashMap();
		map.put("success", false);
		rtn(map, request, response);
		return ;
	}
}
